<HTML><HEAD><TITLE>hash_update(+Table, ++Key, -OldValue, +NewValue)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(hash)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>hash_update(+Table, ++Key, -OldValue, +NewValue)</H1>
Lookup and replace the value stored under Key
<DL>
<DT><EM>Table</EM></DT>
<DD>A hash table
</DD>
<DT><EM>Key</EM></DT>
<DD>a ground term
</DD>
<DT><EM>OldValue</EM></DT>
<DD>Any term
</DD>
<DT><EM>NewValue</EM></DT>
<DD>Any term
</DD>
</DL>
<H2>Description</H2>
A combination of hash_get/3 and hash_set/3, but more efficient
    	because there is only one hash lookup.
<H3>Modes and Determinism</H3><UL>
<LI>hash_update(+, ++, -, +) is semidet
</UL>
<H3>Fail Conditions</H3>
No entry for Key
<H2>Examples</H2>
<PRE>
	?- hash_create(H),
	   hash_set(H, k, hello),
	   hash_update(H, k, Old, world),
	   hash_get(H, k, New).

	Old = hello
	New = world
	Yes (0.00s cpu)

	% sample code based on hash_update/4:
    	hash_inc(H, Key) :-
	    hash_update(H, Key, N0, N1),
	    N1 is N0+1.

    	hash_addto(H, Key, Value) :-
	    hash_update(H, Key, Values, [Value|Values]).
    </PRE>
<H2>See Also</H2>
<A HREF="../../lib/hash/hash_get-3.html">hash_get / 3</A>, <A HREF="../../lib/hash/hash_set-3.html">hash_set / 3</A>
</BODY></HTML>
